import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

declare var bpm: any;
declare var ui: any;
declare var form: any;

@Component({
  templateUrl: './bpm.free.form.html'
})
export class BpmDemoFreeComponentFormComponent implements OnInit {

  // 流程服务
  bs: any;
  // 表单服务
  fs: any;
  menu = null;

  constructor(public route: ActivatedRoute) {
    // 注册表单
    this.fs = new form.FormSimpleService('simpleform', {
      orderObject: { id: 0 },
      keyField: 'id',
      randomFields: ['id']
    });
    // 注册流程
    this.bs = new bpm.BpmService('simpleform', 'zylc');
    // 注册菜单
    this.menu = new ui.TabService('bpm', 's');
    this.menu.setTab('main');
  }

  ngOnInit() {
    this.initData();
  }

  initData() {
    let id = '-1';
    this.route.queryParams.subscribe((res) => {
      if (res.id) {
        id = res.id;
      }
    });
    this.fs.editRowByKey(id, (data) => {
      // 设置流程数据
      this.bs.dataKey = data.id;
      this.bs.data = data;
      // 进来先查询流程信息
      this.bs.findWork();
    });
  }

  loadHistory() {
    this.menu.setTab('history');
    this.bs.loadHistory();
  }

  loadImage() {
    this.menu.setTab('image');
    this.bs.loadImage();
  }
}
